/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.games.epkb.entityClasses;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author plebani
 */
@Entity
@Table(name = "consequent")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Consequent.findAll", query = "SELECT c FROM Consequent c"),
    @NamedQuery(name = "Consequent.findByIdRule", query = "SELECT c FROM Consequent c WHERE c.consequentPK.idRule = :idRule"),
    @NamedQuery(name = "Consequent.findByIdGPIKPI", query = "SELECT c FROM Consequent c WHERE c.consequentPK.idGPIKPI = :idGPIKPI"),
    @NamedQuery(name = "Consequent.findByThreshold", query = "SELECT c FROM Consequent c WHERE c.threshold = :threshold")})
public class Consequent implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ConsequentPK consequentPK;
    @Column(name = "Threshold")
    private String threshold;
    @JoinColumn(name = "Id_GPI_KPI", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private GpiKpi gpiKpi;
    @JoinColumn(name = "Id_Rule", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private AssociationRule associationRule;

    public Consequent() {
    }

    public Consequent(ConsequentPK consequentPK) {
        this.consequentPK = consequentPK;
    }

    public Consequent(String idRule, String idGPIKPI) {
        this.consequentPK = new ConsequentPK(idRule, idGPIKPI);
    }

    public ConsequentPK getConsequentPK() {
        return consequentPK;
    }

    public void setConsequentPK(ConsequentPK consequentPK) {
        this.consequentPK = consequentPK;
    }

    public String getThreshold() {
        return threshold;
    }

    public void setThreshold(String threshold) {
        this.threshold = threshold;
    }

    public GpiKpi getGpiKpi() {
        return gpiKpi;
    }

    public void setGpiKpi(GpiKpi gpiKpi) {
        this.gpiKpi = gpiKpi;
    }

    public AssociationRule getAssociationRule() {
        return associationRule;
    }

    public void setAssociationRule(AssociationRule associationRule) {
        this.associationRule = associationRule;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (consequentPK != null ? consequentPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Consequent)) {
            return false;
        }
        Consequent other = (Consequent) object;
        if ((this.consequentPK == null && other.consequentPK != null) || (this.consequentPK != null && !this.consequentPK.equals(other.consequentPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.games.epkb.entityClasses.Consequent[ consequentPK=" + consequentPK + " ]";
    }
    
}
